import fetch from './fetch'

/**
 * 授权
 */
export const getCode = () => fetch('/rest/start.do')

/**
 * 登录
 */
export const goLogin = (code) => fetch('/rest/login.do', {
  code: code
})

/**
* 获取用户信息
*/
export const getUserInfo = () => fetch('/rest/business/user.do?method=getInfo')

/**
 * 新增答题记录
 * @param level 1-初级，2-中级，3-高级
 */
export const addAnswer = (level) => fetch('/rest/business/answer.do?method=add', {
  level: level
})

/**
 * 判断答题对错
 * @param id  答题记录id
 * @param result 用户选择的答案 判断题: 1-对 0-错 选择题: 选项字符串
 * @param sortNum  题目序号
 */
export const getAnswerResult = (id, result, sortNum) => fetch('/rest/business/answer.do?method=update', {
  id: id,
  result: result,
  sortNum: sortNum
})

/**
 * 判断是否能抽奖
 * @param id  答题记录id
 */
export const getResult = (id) => fetch('/rest/business/answer.do?method=verify', {
  id: id
})

/**
 * 分享
 * @param jsApiList 分享列表
 * @param debug 是否调试
 * @param url 分享连接
 */
export const getShareParams = (jsApiList, debug, url) => fetch('/rest/getShareConfig.do', {
  jsApiList: jsApiList,
  debug: debug,
  url: url
})

/**
 * 抽红包
 * @param code 验证码
 */
export const getMoney = (code) => fetch('/rest/business/record.do?method=grab', {
  code: code
})
